package cn.ubeta.b2c.settings;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import cn.ubeta.b2c.R;
import cn.ubeta.b2c.api.ApiRoot;
import cn.ubeta.b2c.bean.FeedbackInfo;
import cn.ubeta.b2c.common.AnalyseActivity;
import cn.ubeta.b2c.utils.NetworkCallback;
import cn.ubeta.b2c.utils.TitleBarHelper;
import cn.ubeta.b2c.utils.ToastHelper;

import java.io.IOException;

/**
 * Created by denny on 16/9/6.
 */

public class FeedbackActivity extends AnalyseActivity {

    private EditText mEtMessage;
    private EditText mEtContact;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        onCreate(savedInstanceState, R.layout.activity_feedback);
        TitleBarHelper.setRightAction(this, "提交", v -> submit());

        mEtMessage = (EditText) findViewById(R.id.et_message);
        mEtContact = (EditText) findViewById(R.id.et_contact);
    }

    /**
     * 提交意见反馈
     */
    private void submit() {
        String message = mEtMessage.getEditableText().toString();
        if (TextUtils.isEmpty(message)) {
            ToastHelper.show("请填写您的建议");
            return;
        }
        String contact = mEtContact.getEditableText().toString();
        ApiRoot.submitFeedback(message, contact, new NetworkCallback<FeedbackInfo>() {
            @Override
            public void onResponse(FeedbackInfo info) {
                if (info.isSuccess()) {
                    ToastHelper.show("提交成功,谢谢您的反馈!");
                } else {
                    ToastHelper.show("提交错误:" + info.getErrCode() + "," + info.getErrMsg());
                }
            }

            @Override
            public void onFailure(IOException e) {
            }
        });
    }
}
